package com.pureut.order.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.pureut.order.domain.SysSupplierCoding;
import com.pureut.order.service.ISysSupplierCodingService;
import com.sale.common.core.domain.R;
import com.sale.common.core.web.controller.BaseController;
import com.sale.common.mybatis.core.page.PageQuery;
import com.sale.common.mybatis.core.page.TableDataInfo;

import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;


/**
 * @Author: YSL
 * @Date: 2023-07-10 09:24:21
 * @Desc: 供应商类别表Controller
 */
@RestController
@RequestMapping("/supplierCoding")
@Validated
@RequiredArgsConstructor
public class SysSupplierCodingController extends BaseController {

    /**
     * 供应商类别表Service
     */
    private final ISysSupplierCodingService sysSupplierCodingService;

    /**
     * 获取供应商类别列表
     */
    //@SaCheckPermission("system:supplierType:list")
    @GetMapping("/list")
    public TableDataInfo<SysSupplierCoding> list(SysSupplierCoding supplierCoding, PageQuery pageQuery) {
        return sysSupplierCodingService.selectSupplierCodingList(supplierCoding, pageQuery);
    }

    /**
     * 查询单个供应商类别
     */
    //@SaCheckPermission("system:supplierType:query")
    @GetMapping(value = "/{supplierId}")
    public R<SysSupplierCoding> getSysMaterialCodingById(@PathVariable Long supplierId) {
        return R.ok(sysSupplierCodingService.getSupplierCodingById(supplierId));
    }

    /**
     * 新增供应商类别
     */
    //@SaCheckPermission("system:supplierType:add")
    @PostMapping
    public R<Void> add(@RequestBody SysSupplierCoding supplierCoding) {
        return toAjax(sysSupplierCodingService.insertSupplierCoding(supplierCoding));
    }

    /**
     * 修改供应商类别
     */
    //@SaCheckPermission("system:supplierType:edit")
    @PutMapping
    public R<Void> edit(@RequestBody SysSupplierCoding supplierCoding) {
        return toAjax(sysSupplierCodingService.updateSupplierCoding(supplierCoding));
    }

    /**
     * 删除供应商类别
     */
    //@SaCheckPermission("system:supplierType:remove")
    @DeleteMapping(value = "/{idStr}")
    public R<Void> remove(@PathVariable("idStr") String idStr) {
        return toAjax(sysSupplierCodingService.deleteSupplierCoding(idStr));
    }

    /**
     * 供应商类别下拉列表
     */
    @GetMapping("/downList")
    public R<List<HashMap<String, String>>> downList() {
        List<HashMap<String, String>> resultMapList = new ArrayList<>();
        List<SysSupplierCoding> sysSupplierCodings = sysSupplierCodingService.downList();
        for (SysSupplierCoding entity : sysSupplierCodings) {
            HashMap<String, String> resultMap = new HashMap<>();
            resultMap.put("label", entity.getSupplierRules());
            resultMap.put("value", entity.getSupplierCode());
            resultMapList.add(resultMap);
        }
        return R.ok(resultMapList);
    }
}
